﻿@{
    ViewBag.Title = "事故管理";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script type="text/javascript">

    $(document).ready(function () {
        initListCombo();//加载列表的页面下拉框内容
        initcombo();//加载新增页面的下拉框内容
        bindGrid();

        initPassGrid();
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridAccidentManageList");
    });

    function initListCombo() {
        //#region 分中心
        EUIcombobox("#zcenterCode", {
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            //prompt: '--请选择--',
            //editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                EUIcombobox("#zstationCode", {
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    //prompt: '--请选择--',
                    editable: false,
                    OneOption: [{
                        ID: "",
                        Name: "--请选择--"
                    }]
                });
            }
        });
        //#endregion

        //#region 出车分站 初始化
        EUIcombobox("#zstationCode", {
            url: '@Url.Content("~/Medical/GetStation?code=")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var zz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                EUIcombobox("#zambCode", {
                    url: zz,
                    valueField: 'AmbulanceCode',
                    textField: 'PlateNumber',
                    editable: false,
                    OneOption: [{
                        AmbulanceCode: "",
                        PlateNumber: "--请选择--"
                    }]
                });
                var zzz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                EUIcombobox("#zambNumb", {
                    url: zzz,
                    valueField: 'AmbulanceCode',
                    textField: 'CarNumber',
                    editable: false,
                    OneOption: [{
                        AmbulanceCode: "",
                        CarNumber: "--请选择--"
                    }]
                });
            },
            onChange: function (newValue, oldValue) {
                $("#zambNumb").combobox('clear');
                $("#zambCode").combobox('clear');
            }
        });

        //车辆牌号 初始化
        EUIcombobox("#zambCode", {
            url: '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")',
            valueField: 'AmbulanceCode',
            textField: 'PlateNumber',
            editable: true,
            OneOption: [{
                AmbulanceCode: "",
                PlateNumber: "--请选择--"
            }],
            onSelect: function (rec) {

                $("#zambNumb").combobox('setValue', rec.AmbulanceCode);  //根据选择车牌对应的ID ，给车辆编号赋值
            }
        });
        EUIcombobox("#zambNumb", {       //选择车辆编号的联动 初始化
            url: '@Url.Content("~/CM/CarBasicInfo/getCarNumberByID?ID=")',
            valueField: 'AmbulanceCode',
            textField: 'CarNumber',
            editable: true,
            OneOption: [{
                AmbulanceCode: "",
                CarNumber: "--请选择--"
            }],
            onSelect: function (rec) {

                $("#zambCode").combobox('setValue', rec.AmbulanceCode);  //根据选择车辆编号对应的ID，给车牌号赋值 初始化
            }
        });

        var urlstr = '@Url.Content("~/CM/CarBasicInfo/getDictionarybyTypeID?TypeID=CMACDLevel")';   //事故等级初始化
        $.EUIcombobox("#zAccidentLevel", {
            url: urlstr,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]

        });

        var urlstr = '@Url.Content("~/CM/CarBasicInfo/getDictionarybyTypeID?TypeID=CMACDResponsibility")';   //责任情况初始化
        $.EUIcombobox("#zResponsibility", {
            url: urlstr,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]

        });

        $('#zAccidentTimeStart').datetimebox('setValue', $.GetMonthFirstday());
        $('#zAccidentTimeEnd').datetimebox('setValue', $.GetTomorrow());

  
        } //页面初始化结束

        function initPassGrid()
        {
            var PassPlateNumber = '@ViewData["PassPlateNumber"]';
            var PassCenterCode = '@ViewData["PassCenterCode"]';
            var PassStationCode = '@ViewData["PassStationCode"]';
            var PassCarNumber = '@ViewData["PassCarNumber"]';

            if (PassPlateNumber.length > 0 && PassPlateNumber != null) {  //当PassPlateNumber 有值时（从基础页面过来的），赋值，然后只读

                $('#zcenterCode').combobox('setValue', PassCenterCode);
                $('#zcenterCode').combobox('disable');
                $('#zstationCode').combobox('setValue', PassStationCode);
                $('#zstationCode').combobox('disable');
                $('#zambCode').combobox('setValue', PassPlateNumber);
                $('#zambCode').combobox('disable');
                $('#zambNumb').combobox('setValue', PassCarNumber);
                $('#zambNumb').combobox('disable');
                reSearch();
                //$('div.datagrid-toolbar a').eq(0).hide();
                //$('div.datagrid-toolbar a').eq(1).hide();
            }

        }

        var ambCode = null; //全局变量，选择的车辆ID ，从车辆基础表中来。
        var EditID = null;


        function reSearch() {
            $('#gridAccidentManageList').datagrid({
                pageNumber: 1,
                queryParams: {
                    zAccidentTimeStart: $('#zAccidentTimeStart').datetimebox('getValue'),
                    zAccidentTimeEnd: $('#zAccidentTimeEnd').datetimebox('getValue'),
                    zAccidentLevel: $('#zAccidentLevel').combobox('getValue'),
                    zResponsibility: $('#zResponsibility').combobox('getValue'),
                    zcenterCode: $('#zcenterCode').combobox('getValue'),
                    zstationCode: $('#zstationCode').combobox('getValue'),
                    zambCode: $('#zambCode').combobox('getText'),
                    zambNumb: $('#zambNumb').combobox('getText')
                }
            });
            var ambCode = null; //全局变量，选择的车辆ID ，从车辆基础表中来。
            var EditID = null;

            if ('@ViewData["PassPlateNumber"]' != '' && '@ViewData["PassPlateNumber"]' != null) {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar a').eq(1).hide();
              
            }
            else {
              
                if ('@ViewData["em"]' == 'ALL') {
                    if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                        $('div.datagrid-toolbar a').eq(0).show();
                        $('div.datagrid-toolbar div').eq(0).show();
                        $('div.datagrid-toolbar a').eq(1).show();
                        $('div.datagrid-toolbar div').eq(1).show();

                    } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                        $('div.datagrid-toolbar a').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(1).hide();
                        $('div.datagrid-toolbar a').eq(1).hide();

                    }
                    $('#tt').tabs('enableTab', 1);
                    $('#tt').tabs('enableTab', 2);
                    $('#tt').tabs('enableTab', 3);

                    $('#gridAccidentManageList').datagrid('showColumn', 'detail');

                } else if ('@ViewData["em"]' == 'CENTER') {

                    if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                        $('div.datagrid-toolbar a').eq(0).show();
                        $('div.datagrid-toolbar div').eq(0).show();
                        $('div.datagrid-toolbar a').eq(1).show();
                        $('div.datagrid-toolbar div').eq(1).show();

                    } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                        $('div.datagrid-toolbar a').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(1).hide();
                        $('div.datagrid-toolbar a').eq(1).hide();

                    }

                    $('#tt').tabs('disableTab', 1);
                    $('#tt').tabs('disableTab', 2);
                    $('#tt').tabs('disableTab', 3);

                    $('#gridAccidentManageList').datagrid('showColumn', 'detail');

                } else if ('@ViewData["em"]' == 'STATION' || '@ViewData["em"]' == 'SELF') {
                    $('div.datagrid-toolbar a').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(1).hide();
                    $('div.datagrid-toolbar a').eq(1).hide();

                    $('#gridAccidentManageList').datagrid('hideColumn', 'detail');
                    $('#tt').tabs('disableTab', 1);
                    $('#tt').tabs('disableTab', 2);
                    $('#tt').tabs('disableTab', 3);

                }
            }
        }

        function bindGrid() {
            $('#gridAccidentManageList').datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                singleSelect: true,
                loadMsg: '数据加载中请稍后……',
                url: '@Url.Content("~/CM/AccidentManage/DataLoad")',
            striped: true,
            pagination: true,//启用分页，默认每页10行
            rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
            pageSize: 15,//设置 页容量5为
            pageList: [10, 15, 20],//设置 页容量下拉框
            queryParams: {
                zAccidentTimeStart: $('#zAccidentTimeStart').datetimebox('getValue'),
                zAccidentTimeEnd: $('#zAccidentTimeEnd').datetimebox('getValue'),
                zAccidentLevel: $('#zAccidentLevel').combobox('getValue'),
                zResponsibility: $('#zResponsibility').combobox('getValue'),
                zcenterCode: $('#zcenterCode').combobox('getValue'),
                zstationCode: $('#zstationCode').combobox('getValue'),
                zambCode: $('#zambCode').combobox('getText'),
                zambNumb: $('#zambNumb').combobox('getText')
            },
            frozenColumns: [[
                 { field: "ID", title: "ID", hidden: true },

               { field: "backup1", title: "分中心", width: '5%', align: "center" },
               { field: "EndReportPerson", title: "分站", width: '6%', align: "center" },
               { field: "PlateNumber", title: "车牌号码", width: '7%', align: "center" }, 
               { field: "CarNumber", title: "车辆编号", width: '7%', align: "center" }, //金杯救护车
               { field: "ReportNumber", title: "车辆品牌", width: '7%', align: "center" }, //金杯救护车
               { field: "PersonName", title: "类型", width: '10%', align: "center" }, //金杯救护车
               {
                   field: "InsuranceExplain", title: "事故具体时间", width: '10%', align: "center", formater: $.formatTime


               },//SH5491XJH
               { field: "AccidentAddress", title: "事故地点", width: '28%', align: "center" },
               { field: "Responsibility", title: "责任情况", width: '5%', align: "center" },
               { field: "AccidentLevel", title: "事故等级", width: '8%', align: "center" }
               , {
                   field: "detail", title: "查看", width: '6%', align: "center",
                   formatter: function (value, row, index) {
                       return '<a   style="color:#0099FF;"  id="checkA" class="linkURLcls" onclick="openDetailURL(\'' + row.ID + '\');"  href="javascript:void(0)" >查看</a>';
                   }
               }
              // { field: "Remark", title: "备注", width: '16%', align: "center" },

            ]],

            toolbar: [
               {
                   id: 'butnAddList',
                   text: '新增信息',
                   iconCls: 'icon-add',
                   handler: function () {
                       ClearForm();
                       $('#AccidentDetailDialog').dialog('open');
                       $('#btnedit').linkbutton('disable');
                       $('#btnadd').linkbutton('enable');

                       $.GID("btnedit").style.display = "none";
                       $.GID("btnadd").style.display = "block";
                   }
               }, '-',
               {
                   id: 'butnEditList',
                   text: '修改信息',
                   iconCls: 'icon-edit',
                   handler: function () {
                       var r = $('#gridAccidentManageList').datagrid('getSelected');
                       if (r) {
                           ClearForm();
                           $('#AccidentDetailDialog').dialog('open');

                           $('#btnadd').linkbutton('disable');  //按钮启动
                           $('#btnedit').linkbutton('enable');

                           $.GID("btnadd").style.display = "none";
                           $.GID("btnedit").style.display = "block";

                           EditID = r.ID;

                           getEditACD(EditID); //先获取修改内容

                       }
                       else { $.messager.alert('提示信息', '请选择数据行！') }

                   }
               }
            ],
            onLoadSuccess: function (data) {
                $('.linkURLcls').linkbutton({
                    text: '查看',
                    plain: true,
                    iconCls: 'icon-search'
                });

                if ('@ViewData["PassPlateNumber"]' != '' && '@ViewData["PassPlateNumber"]' != null) {
                    $('div.datagrid-toolbar a').eq(0).hide();
                    $('div.datagrid-toolbar a').eq(1).hide();
                   
                }
                else {
                    if ('@ViewData["em"]' == 'ALL') {
                        if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                            $('div.datagrid-toolbar a').eq(0).show();
                            $('div.datagrid-toolbar div').eq(0).show();
                            $('div.datagrid-toolbar a').eq(1).show();
                            $('div.datagrid-toolbar div').eq(1).show();

                        } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                            $('div.datagrid-toolbar a').eq(0).hide();
                            $('div.datagrid-toolbar div').eq(0).hide();
                            $('div.datagrid-toolbar div').eq(1).hide();
                            $('div.datagrid-toolbar a').eq(1).hide();
                        }
                        $('#tt').tabs('enableTab', 1);
                        $('#tt').tabs('enableTab', 2);
                        $('#tt').tabs('enableTab', 3);
                        $('#gridAccidentManageList').datagrid('showColumn', 'detail');

                    } else if ('@ViewData["em"]' == 'CENTER') {

                        if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                            $('div.datagrid-toolbar a').eq(0).show();
                            $('div.datagrid-toolbar div').eq(0).show();
                            $('div.datagrid-toolbar a').eq(1).show();
                            $('div.datagrid-toolbar div').eq(1).show();

                        } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                            $('div.datagrid-toolbar a').eq(0).hide();
                            $('div.datagrid-toolbar div').eq(0).hide();
                            $('div.datagrid-toolbar div').eq(1).hide();
                            $('div.datagrid-toolbar a').eq(1).hide();
                        }
                        $('#tt').tabs('disableTab', 1);
                        $('#tt').tabs('disableTab', 2);
                        $('#tt').tabs('disableTab', 3);
                        $('#gridAccidentManageList').datagrid('showColumn', 'detail');

                    } else if ('@ViewData["em"]' == 'STATION' || '@ViewData["em"]' == 'SELF') {
                        $('div.datagrid-toolbar a').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(1).hide();
                        $('div.datagrid-toolbar a').eq(1).hide();

                        $('#tt').tabs('disableTab', 1);
                        $('#tt').tabs('disableTab', 2);
                        $('#tt').tabs('disableTab', 3);
                        $('#gridAccidentManageList').datagrid('hideColumn', 'detail');


                    }
                }

            }

        });
    } //列表加载结束

    function openDetailURL(ID) {  //打开查看按钮内容
        $('#AccidentDetailDialog').dialog('open');
        getEditACD(ID);
        $('#btnadd').linkbutton('disable');
        $('#btnedit').linkbutton('disable');

        $.GID("btnadd").style.display = "none";
        $.GID("btnedit").style.display = "none";
    }

    $(window).resize(function () {
        $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridAccidentManageList");
    });
    </script>
}

<div id="TableForm" class="easyui-layout" style="width:auto; height:auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:' 事故管理',iconCls:'icon-custom-cWuZiWeiHu'">
        <div id="SearchBar" data-options="region:'north'" style="overflow: hidden; padding: 10px">
            <table>
                <tr>
                    <td>事故日期：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-datetimebox" style="width: 150px" id="zAccidentTimeStart">
                    </td>
                    <td>至：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-datetimebox" style="width: 150px" id="zAccidentTimeEnd">
                    </td>
                    <td>事故等级：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zAccidentLevel" data-options="panelHeight:'auto'">
                    </td>
                    <td>责任情况：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zResponsibility" data-options="panelHeight:'auto'">
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td align="right">分中心：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zcenterCode">
                    </td>
                    <td>分站：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zstationCode">
                    </td>
                    <td>车牌号码：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zambCode">
                    </td>
                    <td>车辆编号：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zambNumb">
                    </td>
                    <td>
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                </tr>

            </table>
        </div>

        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="gridAccidentManageList"></table>
        </div>

    </div>
</div>

@Html.Partial("~/Areas/CM/Views/AccidentManage/AccidentManageDetail.cshtml")